package test.my.com.myapplicationtest.videoview;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import java.io.File;

import test.my.com.myapplicationtest.R;

/**
 * Created by ThinkPad on 2015/6/27.
 */
public class VideoViewActivity extends Activity implements MediaController.MediaPlayerControl{

    public static final String VIDEO_PATH = "/Download/shipin.mp4";

    private VideoView mVideoView_vv;
    private MediaController mMediaController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_videoview_layout);

        mVideoView_vv = (VideoView) findViewById(R.id.mVideoView_vv);
        mMediaController = new MediaController(this);
        mVideoView_vv.setMediaController(mMediaController);

        if(TextUtils.equals(Environment.getExternalStorageState(),Environment.MEDIA_MOUNTED)){
            Log.e("ah",Environment.getExternalStorageDirectory().getPath()+VIDEO_PATH);
            File videoFile = new File(Environment.getExternalStorageDirectory().getPath()+VIDEO_PATH);
            if(videoFile.exists()){
                mVideoView_vv.setVideoURI(Uri.fromFile(videoFile));
            }else{
                Toast.makeText(this,"bucunzai",Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void start() {
        mVideoView_vv.start();
    }

    @Override
    public void pause() {
        if(mVideoView_vv.isPlaying()){
            mVideoView_vv.pause();
        }
    }

    @Override
    public int getDuration() {
        return mVideoView_vv.getDuration();
    }

    @Override
    public int getCurrentPosition() {
        return mVideoView_vv.getCurrentPosition();
    }

    @Override
    public void seekTo(int pos) {
        mVideoView_vv.seekTo(pos);
    }

    @Override
    public boolean isPlaying() {
        return mVideoView_vv.isPlaying();
    }

    @Override
    public int getBufferPercentage() {
        return mVideoView_vv.getBufferPercentage();
    }

    @Override
    public boolean canPause() {
        return mVideoView_vv.canPause();
    }

    @Override
    public boolean canSeekBackward() {
        return mVideoView_vv.canSeekBackward();
    }

    @Override
    public boolean canSeekForward() {
        return mVideoView_vv.canSeekForward();
    }

    @Override
    public int getAudioSessionId() {
        return mVideoView_vv.getAudioSessionId();
    }
}
